#include "Logger.h"

namespace logging {

Logger::Logger(LogOutput *output, const char *ns, Level currentLevel, Level level)
	: _output(output), 
	  _currentLevel(currentLevel),
	  _level(level), 
	  _msg(std::stringstream::out) {
	int len = strlen(ns);
	_namespace = new char[len+1];
	strncpy(_namespace, ns, len+1);
}

Logger::Logger(const Logger &logger) {
}

Logger::~Logger() {
	delete[] _namespace;
}

void Logger::record() const {
	if ( _currentLevel <= _level ) {
		std::string str = _msg.str();
		_output->log(new Entry(_namespace, _level, str.c_str()));
	}
}

Logger& operator<<(Logger &logger, const end e) {
	// commit entry
	logger.record();
	return logger;
}

}
 
